/* 
 *  Copyright (C) 2007 Dip. Ing. dell'Informazione, University of Pisa, Italy
 *  http://info.iet.unipi.it/~cng/ns2voip/
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
 */
/*
 */

#include <voip_header.h>
#include <stdio.h>

static class VoipHeaderClass : public TclClass {
        public:
                VoipHeaderClass() : TclClass("Application/VoipHeader") {}
                TclObject* create(int, const char*const*) {
                        return (new VoipHeader);
                }
} class_voip_header;

VoipHeader::VoipHeader()
{
        debug_           = false;
        initialized_     = false;
        compression_     = false;
        size_            = 40;

        agent_           = 0;        // base class member
}

int
                VoipHeader::command (int argc, const char*const* argv)
{
        if ( argc == 2  && strcmp (argv[1], "debug") == 0 ) {
                debug_ = true;
                return TCL_OK;

        } else if ( argc == 2  && strcmp (argv[1], "nodebug") == 0 ) {
                debug_ = false;
                return TCL_OK;

        } else if ( argc == 2  && strcmp (argv[1], "compression") == 0 ) {
                compression_ = true;
                size_ = 6;
                return TCL_OK;

        } else if ( argc == 2  && strcmp (argv[1], "nocompression") == 0 ) {
                compression_ = false;
                size_ = 40;
                return TCL_OK;

        } else if ( argc == 2  && strcmp (argv[1], "algorithm") == 0 ) {
                fprintf(stderr, "Header Compression Algorithm. To Be Implemented\n");
                return TCL_ERROR;
        }

        return Application::command (argc, argv);
}

void 
VoipHeader::recvPayload (int size, VoipPayload* data)
{
        int payloadSize = size_ + size;
        agent_->sendmsg(payloadSize, (AppData*)data);
}
